﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Http;

namespace CustomMVCCore
{
    public class OpLog : ActionFilterAttribute ,IAsyncActionFilter
    {
        public string opDesc;

        public OpLog(string op)
        {
            Order = 1;
            opDesc = op;
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            HttpRequest req = filterContext.HttpContext.Request;
            if (Extensions.JsonExtensions.IsAjax(req))
            {
                Trace.WriteLine(DateTime.Now + opDesc + "\n\r");
            }
        }

        //public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        //{
        //    HttpRequest req = filterContext.HttpContext.Request;
        //    if (Extensions.JsonExtensions.IsAjax(req))
        //    {
        //        Trace.WriteLine(DateTime.Now + opDesc + "\n\r");
        //    }
        //    throw new NotImplementedException();
        //}
    }
}
